//
//  CZMainViewController.swift
//  CZ29VVeibo
//
//  Created by apple on 16/6/23.
//  Copyright © 2016年 apple. All rights reserved.
//

import UIKit

class CZMainViewController: UITabBarController {

    override func viewDidLoad() {
        
        

        super.viewDidLoad()
        // 自定义tabBar
        let tabBar = CZTabBar()
        // 设置代理
        tabBar.czDelegate = self
        // 通过KVC 给只读属性赋值
        setValue(tabBar, forKey: "tabBar")
        addChildViewController(CZHomeTableViewController(), title: "首页", imgName: "tabbar_home")
        addChildViewController(CZMessageTableViewController(), title: "消息", imgName: "tabbar_message_center")
        addChildViewController(CZDiscoverTableViewController(), title: "发现", imgName: "tabbar_discover")
        addChildViewController(CZProfleTableViewController(), title: "我", imgName: "tabbar_profile")

    }
    
    func addChildViewController(vc: UIViewController,title: String,imgName: String){
        // 设置title
        vc.title = title
        //tabbar_home_selected
        // 设置image
        vc.tabBarItem.image = UIImage(named: imgName)
        vc.tabBarItem.selectedImage = UIImage(named: "\(imgName)_selected")
        let navC = UINavigationController(rootViewController: vc)
        addChildViewController(navC)
        
    }

}

extension CZMainViewController: CZTabBarDelegate{
    func composeButtonClick() {
        let nav = UINavigationController(rootViewController: CZComposeViewController())
        presentViewController(nav, animated:true, completion: nil)
    }
}
